﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace SmartHotel.MVC.MyFilter
{
    public class MyLogin : Attribute, IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            var cookies = context.HttpContext.Request.Cookies;//从上下文中取出所有cookies
            if (cookies.Any(x => x.Key.Equals("username")))
            {
                //说明登录成功了,
            }
            else {
                context.Result = new RedirectResult("/Member/Login");
            }
        }
    }
}
